//
//  AdoptPigCell.m
//  PigMarket
//
//  Created by 张敬 on 2019/8/14.
//  Copyright © 2019年 pigmarket.oc. All rights reserved.
//

#import "AdoptPigsCell.h"

@interface AdoptPigsCell()

@property (nonatomic, strong) UIView *bgView;

/**
 title
 */
@property (nonatomic , strong) UILabel *titleLab;

/**
 生长周期
 */
@property (nonatomic , strong) UILabel *growthCycleLab;

/**
 排队人数
 */
@property (nonatomic , strong) UILabel *lineUpNumLab;

/**
 猪的图片
 */
@property (nonatomic , strong) UIImageView *pigImgView;

/**
 猪的简介
 */
@property (nonatomic , strong) UILabel *detailPigLab;


@end

@implementation AdoptPigsCell

#pragma mark - lifecycle methods
- (void)setupUI
{
    [self addSubview:self.bgView];
    
    [self.bgView addSubview:self.titleLab];
    [self.bgView addSubview:self.lineUpNumLab];
    [self.bgView addSubview:self.growthCycleLab];
    [self.bgView addSubview:self.pigImgView];
    [self.bgView addSubview:self.detailPigLab];
    
}

- (void)setupLayout
{
    CGFloat w = KScreenWidth - 30;
    {
        _bgView.size = CGSizeMake(KScreenWidth - 30, 116);
        _bgView.mj_x = _bgView.mj_y = 0;
    }
    
    {
        _pigImgView.size = CGSizeMake(92, 92);
        _pigImgView.mj_x = _pigImgView.mj_y = 12;
    }
    
    {
        _titleLab.size = CGSizeMake(100, 22);
        _titleLab.mj_y = 12;
        _titleLab.mj_x = _pigImgView.right + 12;
    }
    
    {
        _lineUpNumLab.size = CGSizeMake(100, 28);
        _lineUpNumLab.mj_y = 10;
        _lineUpNumLab.mj_x = KScreenWidth - _lineUpNumLab.width - 20;
    }
    
    {
        _detailPigLab.size = CGSizeMake(w - _pigImgView.right -22, 36);
        _detailPigLab.mj_y = 41;
        _detailPigLab.mj_x = 12 + _pigImgView.right;
    }
    
    {
        _growthCycleLab.size = CGSizeMake(_detailPigLab.width, 18);
        _growthCycleLab.mj_x = _detailPigLab.mj_x;
        _growthCycleLab.mj_y = _detailPigLab.bottom + 8;
    }
    
    
}


#pragma mark - setter methods

- (void)setVarietyModel:(PigVariety *)varietyModel {
    _varietyModel = varietyModel;
    [self.pigImgView sd_setImageWithURL:[NSURL URLWithString:varietyModel.nameimgName] placeholderImage:[UIImage imageNamed:@"placeholder_small"]];
    self.titleLab.text = varietyModel.varietiesName;
    
    NSString *text = [NSString stringWithFormat:@"当前排队%@人",varietyModel.varietiesId];
    NSMutableAttributedString *aims = [[NSMutableAttributedString alloc] initWithString:text];
    [aims addAttribute:NSForegroundColorAttributeName value:UIColorFromRGB(0x999999) range:NSMakeRange(0, text.length)];
    [aims addAttribute:NSFontAttributeName value:mFont(12) range:NSMakeRange(0, text.length)];
    [aims addAttribute:NSForegroundColorAttributeName value:UIColorFromRGB(0xF25C62) range:NSMakeRange(4, text.length - 5)];
    [aims addAttribute:NSFontAttributeName value:mFont(20) range:NSMakeRange(4, text.length-5)];
    self.lineUpNumLab.attributedText = aims;

    self.growthCycleLab.text = [NSString stringWithFormat:@"生长周期%@个月",varietyModel.cycle];
    self.detailPigLab.text = varietyModel.explainText;
    
}


#pragma mark - getter methods

- (UIView *)bgView
{
    if (!_bgView) {
        _bgView = [UIView makeViewBgColor:mBackgroudColor cornerRadius:5];
    }
    return _bgView;
}


- (UILabel *)titleLab {
    
    if (!_titleLab) {
        _titleLab = [[UILabel alloc] init];
        _titleLab.textColor = UIColorFromRGB(0x333333);
        _titleLab.font = mFont(16);
    }
    return _titleLab;
}


- (UILabel *)lineUpNumLab {
    if (!_lineUpNumLab) {
        _lineUpNumLab = [[UILabel alloc] init];
    }
    return _lineUpNumLab;
}


- (UILabel *)growthCycleLab {
    if (!_growthCycleLab) {
        _growthCycleLab = [[UILabel alloc] init];
        _growthCycleLab.textColor = [UIColor colorWithHexString:@"#929292"];
        _growthCycleLab.font = [UIFont smallFont];
    }
   
    return _growthCycleLab;
}


- (UIImageView *)pigImgView {
    if (!_pigImgView) {
        _pigImgView = [[UIImageView alloc] init];
        _pigImgView.userInteractionEnabled = YES;
        [self addShadowAndCircleCorner:_pigImgView.layer corner:2];
    }
    return _pigImgView;
}


- (UILabel *)detailPigLab {
    if (!_detailPigLab) {
        _detailPigLab = [[UILabel alloc] init];
        _detailPigLab.textColor = [UIColor colorWithHexString:@"#808080"];
        _detailPigLab.font = [UIFont smallFont];
        _detailPigLab.numberOfLines = 0;
    }
    return _detailPigLab;
}


@end
